package com.lanou.web.controller;

import com.lanou.entity.TbItem;
import com.lanou.service.impl.ListServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/rest/item")
public class ListController {
    @Autowired
    private ListServiceImpl listService;

    //删除商品
    @ResponseBody
    @RequestMapping("/delete")
    public Map<String, Object> deleteById(long[] ids) {
        boolean result = listService.deleteById(ids);
        Map<String, Object> map = new HashMap<>();
        if (result) {
            map.put("status", 200);
        } else {
            map.put("status", 300);
        }
        return map;
    }

    //下架商品
    @ResponseBody
    @RequestMapping("/instock")
    public Map<String, Object> instock(long[] ids) {
        boolean tbItem = listService.instock(ids);
        Map<String, Object> map = new HashMap<>();
        if (tbItem) {
            map.put("status", 200);
        } else {
            map.put("status", 300);
        }
        return map;
    }

    //上架商品
    @ResponseBody
    @RequestMapping("/reshelf")
    public Map<String, Object> reshelf(long[] ids) {
        boolean tbItem = listService.reshelf(ids);
        Map<String, Object> map = new HashMap<>();
        if (tbItem) {
            map.put("status", 200);
        } else {
            map.put("status", 300);
        }
        return map;
    }

    //编辑商品
    @ResponseBody
    @RequestMapping("/update")
    public Map<String, Object> updateByIds(TbItem tbItem, String desc, String itemParams, Long itemParamId) {
        System.out.println(itemParamId);
        System.out.println(itemParams);
        boolean result = listService.updateByIds(tbItem, desc, itemParams, itemParamId);
        Map<String, Object> map = new HashMap<>();
        if (result) {
            map.put("status", 200);
        } else {
            map.put("status", 300);
        }
        return map;
    }

}
